/*
 * @lc app=leetcode.cn id=268 lang=javascript
 *
 * [268] 丢失的数字
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {number}
 */
var missingNumber = function(nums) {
  const len = nums.length;
  nums.sort((a, b) => a - b);
  for(let i = 0; i < len - 1; i++) {
    const preNext = nums[i] + 1;
    const next = nums[i + 1];
    if (preNext !== next) {
      return preNext;
    }
  }

  return nums[0] === 0 ? len : 0;
};
// @lc code=end

